package cn.modificator.relationtree.widgets;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SeekBar;

import cn.modificator.relationtree.utils.DeviceUtil;

/**
 * Created by Modificator
 * time: 2017/9/18.下午3:03
 * des:create file and achieve model
 */


public class RangeSeekBar extends View {
    //进度条高度
    private int lineHeight = DeviceUtil.dp2Px(4);
    //按钮大小
    private int thumbSize = DeviceUtil.dp2Px(25);
    Paint paint = new Paint();

    public RangeSeekBar(Context context) {
        this(context, null);
    }

    public RangeSeekBar(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RangeSeekBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        paint.setColor(0xff000000);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(0xff888888);

        RectF lineDrawArea = new RectF();
        lineDrawArea.left = thumbSize / 2f;
        lineDrawArea.top = (thumbSize - lineHeight) / 2f;
        lineDrawArea.right = getWidth() - thumbSize / 2f;
        lineDrawArea.bottom = lineDrawArea.top + lineHeight;
        canvas.drawRoundRect(lineDrawArea, lineHeight, lineHeight, paint);

        paint.setColor(0x800ff00f);
        RectF leftThumbArea = new RectF();
        leftThumbArea.top = 0;
        leftThumbArea.left = 0;
        leftThumbArea.right = thumbSize;
        leftThumbArea.bottom = thumbSize;
        canvas.drawOval(leftThumbArea, paint);
    }
}
